package com.activitycode.adapter;

import java.util.List;

import com.activitycode.datamodel.modelinfo.CommentInfo;
import com.activitycode.tools.TimeTools;
import com.activitycode.util.CommConstant;
import com.helixinsoft.texi.driver.R;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;


public class CommentAdapter extends BaseAdapter{
	
	public Context context;
	private List<CommentInfo> infoList;
	public final String Tag ="HistoryAdapter";
	public CommentAdapter adapter;
	private ImageLoader imageLoader;
	private DisplayImageOptions options;
	
	
	public CommentAdapter(Context ct,List<CommentInfo> list){
		this.context = ct;
		this.infoList = list;
		
		adapter = this;
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return infoList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return infoList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder viewHolder = null;
		  
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.adapter_comment, null);
            viewHolder.name = (TextView) convertView.findViewById(R.id.adapter_comment_name); 
            viewHolder.add_time = (TextView) convertView.findViewById(R.id.adapter_comment_time);
            viewHolder.content = (TextView) convertView.findViewById(R.id.adapter_comment_content);
            
            viewHolder.rating = (RatingBar) convertView.findViewById(R.id.adapter_comment_rating); 
            
            convertView.setTag(viewHolder);
        } else {
        	
            viewHolder = (ViewHolder) convertView.getTag();
        }
        
        if(infoList.get(position).user_name!=null&&infoList.get(position).user_name.length()>=11){
        	viewHolder.name.setText("");
        }
        
        String addTime = infoList.get(position).evaluate_time;//TimeTools.getStampTime(infoList.get(position).add_time);
        viewHolder.add_time.setText(addTime);
        viewHolder.content.setText(infoList.get(position).evaluate_content);
        if(infoList.get(position).evaluate_level==null){
        	infoList.get(position).evaluate_level = "5";
		}
        try {
        	float ra = Float.parseFloat(infoList.get(position).evaluate_level);
            viewHolder.rating.setRating(ra);
		} catch (Exception e) {
			// TODO: handle exception
		}
        
        
		return convertView;
	}
	public final static class ViewHolder {
        TextView name,add_time,content;
        RatingBar rating;
        
    }
	

	
	
	

}